package chainOfResponsibility;

import gameBasics.GameObject;
import tank.EnemyTank;

public class ETankETankCollider implements Collider{

    /**
     * 敌对坦克与敌对坦克碰撞
     * @param o1 坦克对象
     * @param o2 坦克对象
     */
    @Override
    public boolean collide(GameObject o1, GameObject o2) {
        if(o1 instanceof EnemyTank enemyTank1 && o2 instanceof EnemyTank enemyTank2){
            collideWith(enemyTank1, enemyTank2);
        }

        return true;
    }

    /**
     * 坦克与坦克的碰撞检测
     * @param enemyTank1 敌对坦克对象
     * @param enemyTank2 敌对坦克对象
     */
    private void collideWith(EnemyTank enemyTank1, EnemyTank enemyTank2) {
        if(enemyTank1.getRectangle().intersects(enemyTank2.getRectangle())){
            enemyTank1.back();
            enemyTank2.back();
        }
    }

}
